var ECharts;
$(document).ready(function () {
    require.config({
        baseUrl: ctx + '/resource/plugins/echarts4',
        paths: {
            echarts: 'echarts',
            roma: 'theme/roma',
        }
    });
    require(
        [
            'echarts',
            'roma'
        ],
        function (ec) {
            ECharts = ec;
            MysqlInformationViewController();//数据库基本信息
            mysql_state = ECharts.init(document.getElementById('mysql_state'), 'roma');//数据库状态
            queryMysqlState();
            mysql_jd = ECharts.init(document.getElementById('mysql_jd'), 'roma');//节点主库状态
            queryMysqlJd();
            queryMysqlInnodb();//Innodb 引擎
            queryMysqlIo();// 表空间的I/O
        }
    );
});

var infoList = [];//数据库基本信息
infoList.push("PM-00-03-009-15");
infoList.push("PM-00-03-011-12");
infoList.push("PM-00-04-006-01");
infoList.push("PM-00-03-011-14");
infoList.push("PM-00-03-011-16");
infoList.push("PM-00-03-011-09");
infoList.push("PM-00-03-009-03");
infoList.push("PM-00-03-011-11");
infoList.push("PM-00-03-011-17");
infoList.push("PM-00-03-011-13");
infoList.push("PM-00-03-009-12");
infoList.push("PM-00-03-011-15");
infoList.push("PM-00-03-011-10");
infoList.push("CM-00-03-001-02");


//===============================
var poolList = [];//IO
poolList.push("PM-00-03-011-58");
poolList.push("PM-00-03-011-59");
poolList.push("PM-00-03-011-60");
poolList.push("PM-00-03-011-61");
//=====================================
var InnodbList = [];//Innodb
InnodbList.push("PM-00-03-011-01");
InnodbList.push("PM-00-03-011-02");
InnodbList.push("PM-00-03-011-03");
InnodbList.push("PM-00-03-011-04");
InnodbList.push("PM-00-03-011-05");
InnodbList.push("PM-00-03-011-06");
InnodbList.push("PM-00-03-011-07");
InnodbList.push("PM-00-03-011-08");


//数据库基本信息
function MysqlInformationViewController() {
    var str = infoList.toString();
    $.ajax({
        url: ctx + "/load/queryInfo",
        type: "post",
        data: "EXT_UNIT_ID=" + EXT_UNIT_ID + "&RESU=" + str,
        success: function (data) {
            var map = JSON.parse(data);
            // var list = map["PM-00-03-009-15"];
            // var list1 = map["PM-00-03-011-12"];
            // var list2 = map["PM-00-04-006-01"];
            // var list3 = map["PM-00-03-011-14"];
            // var list4 = map["PM-00-03-011-16"];
            // var list5 = map["PM-00-03-011-09"];
            // var list6 = map["PM-00-03-009-03"];
            // var list7 = map["PM-00-03-011-11"];
            // var list8 = map["PM-00-03-011-17"];
            // var list9 = map["PM-00-03-011-13"];
            // var list10 = map["PM-00-03-009-12"];
            // var list11 = map["PM-00-03-011-15"];
            // var list12 = map["PM-00-03-011-10"];
            var list13 = map["CM-00-03-001-02"];
            var tablel = "";
            if (list13.length == 0) {
                tablel += "<tr>" +
                    "<th><span >" + "指标名" + "</span></th>" +
                    "<th><span >" + "采集值" + "</span></th>" +
                    "</tr>" + "<tr>" +
                    "<td><span >" + "暂无数据" + "</span></td>" +
                    "</tr>";
            } else {
                tablel += "<tr>" +
                    "<th><span >" + "指标名" + "</span></th>" +
                    "<th><span >" + "采集值" + "</span></th>" +
                    "</tr>" + "<tr>" +
                    "<td><span >" + list13[0].KPI_NAME + "</span></td>" +
                    "<td><span >" + list13[0].KPI_VALUE + "</span></td>" +
                    "</tr>";
            }
            $("#mysql_info").append(tablel);
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

//数据库状态
//FM-00-03-001-01
function queryMysqlState() {
    $.ajax({
        url: ctx + "/load/queryNum",
        type: "post",
        data: "EXT_UNIT_ID=" + EXT_UNIT_ID + "&KPI_CODE=" + "FM-00-03-001-01" + "&DATE_TYPE=" + DATE_TYPE,
        success: function (data) {
            var cpuState = JSON.parse(data);
            var mydata;
            for(var i=0;i<cpuState.length;i++){
                var a = cpuState[i].SUCCESS_VALUE;
                var b = cpuState[i].COUNT_VALUE;
            }
            option = {
                tooltip: {
                    formatter: "{a} <br/>{b} : {c}%"
                },
                toolbox: {
                    show: true,
                    feature: {
                        mark: {show: true},
                        // restore: {show: true},
                        // saveAsImage: {show: true}
                    }
                },
                series: [
                    {
                        name: '',
                        type: 'gauge',
                        splitNumber: 10,       // 分割段数，默认为5
                        axisLine: {            // 坐标轴线
                            lineStyle: {       // 属性lineStyle控制线条样式
                                color: [[0.2, '#ff4500'], [0.8, '#48b'], [1, '#228b22']],
                                width: 8
                            }
                        },
                        axisTick: {            // 坐标轴小标记
                            splitNumber: 10,   // 每份split细分多少段
                            length: 12,        // 属性length控制线长
                            lineStyle: {       // 属性lineStyle控制线条样式
                                color: 'auto'
                            }
                        },
                        axisLabel: {           // 坐标轴文本标签，详见axis.axisLabel
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                color: 'auto'
                            }
                        },
                        splitLine: {           // 分隔线
                            show: true,        // 默认显示，属性show控制显示与否
                            length: 30,         // 属性length控制线长
                            lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
                                color: 'auto'
                            }
                        },
                        pointer: {
                            width: 5
                        },
                        title: {
                            show: true,
                            offsetCenter: [0, '-40%'],       // x, y，单位px
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                fontWeight: 'bolder'
                            }
                        },
                        detail: {
                            formatter: '{value}%',
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                color: 'auto',
                                fontWeight: 'bolder'
                            }
                        },
                        data: []
                    }
                ]
            };//仪表盘结束
            var cpuName = "";
            var succ = [];
            var sun = [];
            var p_value = 0;
            var q_value = 0;
            var succs = 0;
            var sums = 0;
            if (DATE_TYPE == "showYear") {
                for (var j = 0; j < cpuState.length; j++) {
                    p_value = parseInt(cpuState[j].SUCCESS_VALUE);
                    succ.push(p_value);
                    q_value = parseInt(cpuState[j].COUNT_VALUE);
                    sun.push(q_value);
                    cpuName = cpuState[j].KPI_NAME;
                }
                for (var k = 0; k < succ.length; k++) {
                    succs += succ[k];
                    sums += sun[k];
                }
                /*alert(succs);alert(sums);*/
                mydata = [{value: parseInt(succs / sums * 100), name: cpuName}];
            } else {
                for (var i = 0; i < cpuState.length; i++) {
                    mydata = [{
                        value: parseInt(cpuState[i].SUCCESS_VALUE / cpuState[i].COUNT_VALUE * 100),
                        name: cpuState[i].KPI_NAME
                    }];
                }
            }

            if (a == undefined || b == undefined) {
                var table = "<h3 style='margin-top: 180px;padding-left: 140px;'>" + "暂无数据" + "</h3>";
                $("#mysql_state").html(table);
            } else {
                option.series[0].data = mydata;
                mysql_state.setOption(option);
            }
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });

}

//节点主库状态
//FM-00-03-001-10
function queryMysqlJd() {
    $.ajax({
        url: ctx + "/load/queryNum",
        type: "post",
        data: "EXT_UNIT_ID=" + EXT_UNIT_ID + "&KPI_CODE=" + "FM-00-03-001-10" + "&DATE_TYPE=" + DATE_TYPE,
        success: function (data) {
            var cpuState = JSON.parse(data);
            var mydata;
            for(var i=0;i<cpuState.length;i++){
                var a = cpuState[i].SUCCESS_VALUE;
                var b = cpuState[i].COUNT_VALUE;
            }
            option = {
                tooltip: {
                    formatter: "{a} <br/>{b} : {c}%"
                },
                toolbox: {
                    show: true,
                    feature: {
                        mark: {show: true},
                        // restore: {show: true},
                        // saveAsImage: {show: true}
                    }
                },
                series: [
                    {
                        name: '',
                        type: 'gauge',
                        splitNumber: 10,       // 分割段数，默认为5
                        axisLine: {            // 坐标轴线
                            lineStyle: {       // 属性lineStyle控制线条样式
                                color: [[0.2, '#ff4500'], [0.8, '#48b'], [1, '#228b22']],
                                width: 8
                            }
                        },
                        axisTick: {            // 坐标轴小标记
                            splitNumber: 10,   // 每份split细分多少段
                            length: 12,        // 属性length控制线长
                            lineStyle: {       // 属性lineStyle控制线条样式
                                color: 'auto'
                            }
                        },
                        axisLabel: {           // 坐标轴文本标签，详见axis.axisLabel
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                color: 'auto'
                            }
                        },
                        splitLine: {           // 分隔线
                            show: true,        // 默认显示，属性show控制显示与否
                            length: 30,         // 属性length控制线长
                            lineStyle: {       // 属性lineStyle（详见lineStyle）控制线条样式
                                color: 'auto'
                            }
                        },
                        pointer: {
                            width: 5
                        },
                        title: {
                            show: true,
                            offsetCenter: [0, '-40%'],       // x, y，单位px
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                fontWeight: 'bolder'
                            }
                        },
                        detail: {
                            formatter: '{value}%',
                            textStyle: {       // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                                color: 'auto',
                                fontWeight: 'bolder'
                            }
                        },
                        data: []
                    }
                ]
            };//仪表盘结束
            var cpuName = "";
            var succ = [];
            var sun = [];
            var p_value = 0;
            var q_value = 0;
            var succs = 0;
            var sums = 0;
            if (DATE_TYPE == "showYear") {
                for (var j = 0; j < cpuState.length; j++) {
                    p_value = parseInt(cpuState[j].SUCCESS_VALUE);
                    succ.push(p_value);
                    cpuName = cpuState[j].KPI_NAME;
                    q_value = parseInt(cpuState[j].COUNT_VALUE);
                    sun.push(q_value);
                    cpuName = cpuState[j].KPI_NAME;
                }
                for (var k = 0; k < succ.length; k++) {
                    succs += succ[k];
                    sums += sun[k];
                }
                /*alert(succs);alert(sums);*/
                // mydata = [{value: parseInt(succs / sums * 100), name: cpuName}];
                mydata = [{value: parseInt(0 / sums * 100), name: cpuName}];
            } else {
                for (var i = 0; i < cpuState.length; i++) {
                    // mydata = [{value: parseInt(cpuState[i].SUCCESS_VALUE / cpuState[i].COUNT_VALUE * 100), name: cpuState[i].KPI_NAME}];
                    if (cpuState[i].SUCCESS_VALUE == undefined) {
                        mydata = [{value: 0, name: cpuState[i].KPI_NAME}];
                    } else {
                        mydata = [{
                            value: parseInt(cpuState[i].SUCCESS_VALUE / cpuState[i].COUNT_VALUE * 100),
                            name: cpuState[i].KPI_NAME
                        }];
                    }
                }
            }

            if (a == undefined || b == undefined) {
                var table = "<h3 style='margin-top: 180px;padding-left: 140px;'>" + "暂无数据" + "</h3>";
                $("#mysql_jd").html(table);
            } else {
                option.series[0].data = mydata;
                mysql_jd.setOption(option);
            }
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });

}

//Innodb 引擎
function queryMysqlInnodb() {
    var str = InnodbList.toString();
    $.ajax({
        url: ctx + "/load/queryTable",
        type: "post",
        data: "EXT_UNIT_ID=" + EXT_UNIT_ID + "&RESU=" + str + "&DATE_TYPE=" + DATE_TYPE,
        success: function (data) {
            var map = JSON.parse(data);
            console.log(Object.keys(map).length);
            var list1 = map["PM-00-03-011-01"];
            var list2 = map["PM-00-03-011-02"];
            var list3 = map["PM-00-03-011-03"];
            var list4 = map["PM-00-03-011-04"];
            var list5 = map["PM-00-03-011-05"];
            var list6 = map["PM-00-03-011-06"];
            var list7 = map["PM-00-03-011-07"];
            var list8 = map["PM-00-03-011-08"];

            var table = "";
            if (list1.length == 1 && list2.length == 1 && list3.length == 1 && list4.length == 1 && list5.length == 1 && list6.length == 1 && list7.length == 1 && list8.length == 1) {
                table += "<tr>" +
                    "<th><span >" + list1[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list2[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list3[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list4[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list5[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list6[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list7[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list8[0].KPI_NAME + "</span></th></tr>" +
                    "<tr><td><span >" + "暂无数据" + "</span></td></tr>";
            }
            else {
                table += "<tr>" +
                    "<th><span >" + list1[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list2[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list3[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list4[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list5[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list6[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list7[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list8[0].KPI_NAME + "</span></th>" +
                    "</tr>";
                if (DATE_TYPE == "showYear") {
                    var UnitIdList = new Array()   //结果ID列表
                    var succList2 = new Array();
                    var countList2 = new Array();
                    var AvgList2 = new Array() //结果VALUE列表
                    var AvgList3 = new Array();
                    var AvgList4 = new Array();
                    var AvgList5 = new Array();
                    var AvgList6 = new Array();
                    var AvgList7 = new Array();
                    var AvgList8 = new Array();
                    var AvgList9 = new Array();

                    var map = new Map()            //结果map
                    var iSameLine = 0 //相同条数标志位
                    var SumValue2 = 0 //和值
                    var SumValue3 = 0;
                    var SumValue4 = 0;
                    var SumValue5 = 0;
                    var SumValue6 = 0;
                    var SumValue7 = 0;
                    var SumValue8 = 0;
                    var SumValue9 = 0;

                    var gsuccValue = 0
                    var gcountValue = 0
                    var sTreeUnitId   //上一次ID

                    var str           //原始unit_id
                    var sUnitId       //名称
                    var succValue
                    var countValue
                    var AvgValue2
                    var AvgValue3
                    var AvgValue4
                    var AvgValue5
                    var AvgValue6
                    var AvgValue7
                    var AvgValue8
                    var AvgValue9

                    for (i = 1; i < list1.length; i++) {
                        str = list1[i].UNIT_ID;
                        sUnitId = str.split("-")[4];
                        succValue = parseInt(list1[i].SUCCESS_VALUE);
                        countValue = parseInt(list1[i].COUNT_VALUE);
                        AvgValue2 = parseInt(list2[i].AVG_VALUE)  //获取对应的avg_value/
                        AvgValue3 = parseInt(list3[i].AVG_VALUE);
                        AvgValue4 = parseInt(list4[i].AVG_VALUE);
                        AvgValue5 = parseInt(list5[i].AVG_VALUE);
                        AvgValue6 = parseInt(list6[i].AVG_VALUE);
                        AvgValue7 = parseInt(list7[i].AVG_VALUE);
                        AvgValue8 = parseInt(list8[i].AVG_VALUE);

                        if (i == 0) {                    //第一次进入标志位强制相同
                            sTreeUnitId = sUnitId;
                        }
                        if (sTreeUnitId == sUnitId) {   //本次循环获取id与上次相同累加并继续下次循环
                            gsuccValue = gsuccValue + succValue;
                            gcountValue = gcountValue + countValue;
                            SumValue2 = SumValue2 + AvgValue2;
                            SumValue3 = SumValue3 + AvgValue3;
                            SumValue4 = SumValue4 + AvgValue4;
                            SumValue5 = SumValue5 + AvgValue5;
                            SumValue6 = SumValue6 + AvgValue6;
                            SumValue7 = SumValue7 + AvgValue7;
                            SumValue8 = SumValue8 + AvgValue8;
                            SumValue9 = SumValue9 + AvgValue9;

                            iSameLine = iSameLine + 1     //桩相同条数
                            if (i == list1.length - 1) {   //循环到最后一次如果与上一次相同直接写出结果
                                UnitIdList.push(sTreeUnitId);
                                succList2.push(gsuccValue);
                                countList2.push(gcountValue);
                                AvgList2.push(SumValue2);
                                AvgList3.push(SumValue3);
                                AvgList4.push(SumValue4);
                                AvgList5.push(SumValue5);
                                AvgList6.push(SumValue6);
                                AvgList7.push(SumValue7);
                                AvgList8.push(SumValue8);
                                AvgList9.push(SumValue9);

                                map.set(sTreeUnitId, SumValue2)
                            }
                        } else {
                            UnitIdList.push(sTreeUnitId);
                            succList2.push(gsuccValue);
                            countList2.push(gcountValue);
                            AvgList2.push(SumValue2);
                            AvgList3.push(SumValue3);
                            AvgList4.push(SumValue4);
                            AvgList5.push(SumValue5);
                            AvgList6.push(SumValue6);
                            AvgList7.push(SumValue7);
                            AvgList8.push(SumValue8);
                            AvgList9.push(SumValue9);

                            map.set(sTreeUnitId, SumValue2);
                            iSameLine = 1
                            sTreeUnitId = sUnitId
                            gsuccValue = succValue;
                            gcountValue = countValue;
                            SumValue2 = AvgValue2
                            SumValue3 = AvgValue3;
                            SumValue4 = AvgValue4;
                            SumValue5 = AvgValue5;
                            SumValue6 = AvgValue6;
                            SumValue7 = AvgValue7;
                            SumValue8 = AvgValue8;
                            SumValue9 = AvgValue9;
                        }
                    }

                    for (var c = 1; c < UnitIdList.length; c++) {
                        table += "<tr>" +
                            "<td><span >" + UnitIdList[c] + "</span></td>" +
                            "<td><span >" + succList2[c] / countList2[c] * 100 / iSameLine + "%" + "</span></td>" +
                            "<td><span >" + AvgList2[c] / iSameLine + "</span></td>" +
                            "<td><span >" + AvgList3[c] / iSameLine + "</span></td>" +
                            "<td><span >" + AvgList4[c] / iSameLine + "</span></td>" +
                            "<td><span >" + AvgList5[c] / iSameLine + "</span></td>" +
                            "<td><span >" + AvgList6[c] / iSameLine + "</span></td>" +
                            "<td><span >" + AvgList7[c] / iSameLine + "</span></td>" +
                            // "<td><span >" + AvgList8[c] / iSameLine + "</span></td>" +
                            // "<td><span >" + AvgList9[c] / iSameLine + "</span></td>" +//注释掉部分为测试删除数据
                            "</tr>";
                    }
                    $("#row10").css("height", (UnitIdList.length) * 34 + 14 + 34 + 34);

                } else {
                    for (var i = 1; i < list1.length; i++) {
                        var str = list1[i].UNIT_ID;
                        var PORTNAME = str.split("-")[4];
                        table += "<tr>" +
                            "<td><span >" + list1[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list2[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list3[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list4[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list5[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list6[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list7[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list8[i].AVG_VALUE + "</span></td>" +
                            "</tr>";
                    }
                    $("#row10").css("height", list1.length * 34 + 14 + 34 + 34);
                }
            }
            $("#Innodb").append(table);
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}


//表空间的I/O
// avg_time_wait  PM-00-03-011-58    avg_time_read   PM-00-03-011-59   avg_time_write  PM-00-03-011-60   avg_time_misc   PM-00-03-011-61
function queryMysqlIo() {
    var str = poolList.toString();
    $.ajax({
        url: ctx + "/load/queryTable",
        type: "post",
        data: "EXT_UNIT_ID=" + EXT_UNIT_ID + "&RESU=" + str + "&DATE_TYPE=" + DATE_TYPE,
        success: function (data) {
            var map = JSON.parse(data);
            var list1 = map["PM-00-03-011-58"];
            var list2 = map["PM-00-03-011-59"];
            var list3 = map["PM-00-03-011-60"];
            var list4 = map["PM-00-03-011-61"];
            var table = "";
            if (list1.length == 0 && list2.length == 0 && list3.length == 0 && list4.length == 0) {
                table +=
                    "<tr><th><span >" + "指标名" + "</span></th></tr>" +
                    "<tr><td><span >" + "暂无数据" + "</span></td></tr>";
            } else {
                table += "<tr>" +
                    "<th><span >" + "Event_Name" + "</span></th>" +
                    "<th><span >" + list1[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list2[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list3[0].KPI_NAME + "</span></th>" +
                    "<th><span >" + list4[0].KPI_NAME + "</span></th></tr>";
                if (DATE_TYPE == "showYear") {
                    var UnitIdList = new Array()   //结果ID列表
                    var succList2 = new Array();
                    var countList2 = new Array();
                    var AvgList1 = new Array() //结果VALUE列表
                    var AvgList2 = new Array() //结果VALUE列表
                    var AvgList3 = new Array();
                    var AvgList4 = new Array();

                    var map = new Map()            //结果map
                    var iSameLine = 0 //相同条数标志位
                    var SumValue1 = 0 //和值
                    var SumValue2 = 0 //和值
                    var SumValue3 = 0;
                    var SumValue4 = 0;

                    var gsuccValue = 0
                    var gcountValue = 0
                    var sTreeUnitId   //上一次ID

                    var str           //原始unit_id
                    var sUnitId       //名称
                    var succValue
                    var countValue
                    var AvgValue1
                    var AvgValue2
                    var AvgValue3
                    var AvgValue4

                    // console.log('列表条数为' + list1.length)
                    for (i = 1; i < list1.length; i++) {
                        str = list1[i].UNIT_ID;
                        sUnitId = str.split("-")[4];
                        succValue = parseInt(list1[i].SUCCESS_VALUE);
                        countValue = parseInt(list1[i].COUNT_VALUE);
                        AvgValue1 = parseInt(list1[i].AVG_VALUE)
                        AvgValue2 = parseInt(list2[i].AVG_VALUE)  //获取对应的avg_value/
                        AvgValue3 = parseInt(list3[i].AVG_VALUE);
                        AvgValue4 = parseInt(list4[i].AVG_VALUE);
                        if (i == 0) {                    //第一次进入标志位强制相同
                            sTreeUnitId = sUnitId;
                        }
                        if (sTreeUnitId == sUnitId) {   //本次循环获取id与上次相同累加并继续下次循环
                            gsuccValue = gsuccValue + succValue;
                            gcountValue = gcountValue + countValue;
                            SumValue1 = SumValue1 + AvgValue1;
                            SumValue2 = SumValue2 + AvgValue2;
                            SumValue3 = SumValue3 + AvgValue3;
                            SumValue4 = SumValue4 + AvgValue4;

                            iSameLine = iSameLine + 1     //桩相同条数
                            if (i == list1.length - 1) {   //循环到最后一次如果与上一次相同直接写出结果
                                UnitIdList.push(sTreeUnitId);
                                succList2.push(gsuccValue);
                                countList2.push(gcountValue);
                                AvgList1.push(SumValue1);
                                AvgList2.push(SumValue2);
                                AvgList3.push(SumValue3);
                                AvgList4.push(SumValue4);

                                map.set(sTreeUnitId, SumValue2)
                            }
                        } else {
                            UnitIdList.push(sTreeUnitId);
                            succList2.push(gsuccValue);
                            countList2.push(gcountValue);
                            AvgList1.push(SumValue1);
                            AvgList2.push(SumValue2);
                            AvgList3.push(SumValue3);
                            AvgList4.push(SumValue4);

                            map.set(sTreeUnitId, SumValue2);
                            iSameLine = 1
                            sTreeUnitId = sUnitId
                            gsuccValue = succValue;
                            gcountValue = countValue;
                            SumValue1 = AvgValue1;
                            SumValue2 = AvgValue2
                            SumValue3 = AvgValue3;
                            SumValue4 = AvgValue4;

                        }
                    }

                    for (var c = 1; c < UnitIdList.length; c++) {
                        table += "<tr>" +
                            "<td><span >" + UnitIdList[c] + "</span></td>" +
                            // "<td><span >" + succList2[c] / countList2[c] * 100 / iSameLine + "%" + "</span></td>" +
                            "<td><span >" + AvgList1[c] / iSameLine + "</span></td>" +
                            "<td><span >" + AvgList2[c] / iSameLine + "</span></td>" +
                            "<td><span >" + AvgList3[c] / iSameLine + "</span></td>" +
                            "<td><span >" + AvgList4[c] / iSameLine + "</span></td>" +
                            "</tr>";
                    }
                    $("#row20").css("height", (UnitIdList.length) * 34 + 14 + 34 + 34);

                } else {
                    for (var i = 1; i < list1.length; i++) {
                        var str = list1[i].UNIT_ID;
                        var PORTNAME = str.split("-")[4];
                        table += "<tr>" +
                            "<td><span >" + PORTNAME + "</span></td>" +
                            "<td><span >" + list1[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list2[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list3[i].AVG_VALUE + "</span></td>" +
                            "<td><span >" + list4[i].AVG_VALUE + "</span></td>" +
                            "</tr>";
                    }
                    $("#row20").css("height", (list1.length) * 34 + 14 + 34 + 34);
                }
            }
            $("#Io").append(table);
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

// //按钮事件
// $(".rad_1").click(function () {
//     var id = $(this).attr('for');
//     mysql_state.clear();//数据库状态
//     mysql_jd.clear();//节点主库状态
//     $("#mysql_info tr").remove();
//     $("#mysql_info1 tr").remove();
//     $("#Innodb tr").remove();
//     $("#Io tr").remove();
//     MysqlInformationViewController(id);
//     queryMysqlState(id);//数据库状态
//     queryMysqlJd(id);//节点主库状态
//     queryMysqlInnodb(id);//Innodb 引擎
//     queryMysqlIo(id);//表空间的I/O
//
// });

